import QtQuick 2.6
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0
import Qt.labs.controls 1.0
import QtQuick.XmlListModel 2.0

import "../template" as Template
import "../js/LoginNavigator.qml.js" as Ln

Template.Navigator {
    id: nav
    title: "登录"

    property string directqml: ""

    function messageReceived(action, data) {

    }

    Settings {
        id: setting
        category: "account"
        property alias name: accountTxt.text
    }

    XmlListModel {
        id: xmlModel_School
        source: http.build( "/school.xml", {})
        query: "/schools/school"
        XmlRole { name: "id"; query: "id/string()" }
        XmlRole { name: "name"; query: "name/string()" }
    }
   Template.InputView {
            id: dsds

    }

    Flickable {
        id: flickable
        anchors.fill: parent
        contentWidth: parent.width
        contentHeight:720

        ScrollIndicator.vertical: ScrollIndicator { }


        Pane {
            anchors.fill: parent
            ColumnLayout{

                anchors.horizontalCenter: parent.horizontalCenter
                spacing: 12

                Image {
                    id: identity
                    source: "../images/identity.png"
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                Row{
                    spacing: 12
                    Label {
                        text: qsTr("姓名")
                        verticalAlignment: Text.AlignVCenter
                        height: accountTxt.height
                    }

                    TextField {
                        id: accountTxt
                        width: implicitWidth * 1.5
                        Keys.onReturnPressed: passText.focus=true
                        Keys.onEnterPressed: passText.focus=true
                    }
                }

                Row{
                    spacing: 12
                    Label {
                        text: qsTr("密码")
                        verticalAlignment: Text.AlignVCenter
                        height: passText.height
                    }
                    TextField {
                        id: passText
                        width: implicitWidth * 1.5
                        focus:true
                        echoMode: TextInput.Password
                        Keys.onReturnPressed: Ln.login()
                        Keys.onEnterPressed: Ln.login()
                        Keys.onTabPressed: accountTxt.focus = true
                    }
                }

                Row {
                    spacing: 12
                    Label {
                        text: qsTr("驾校")
                        verticalAlignment: Text.AlignVCenter
                        height: txtCompany.height
                    }

                    ComboBox {
                        id: txtCompany
                        model: xmlModel_School
                        width: passText.width
                        textRole: "name"
                        currentIndex: 0
                    }
                }
                Button {
                    text: qsTr("登录")
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: implicitWidth * 1.5

                    onClicked: Ln.login()
                }



                RowLayout {
                    width: parent.width
                    ToolButton {
                        text: "注册账号"
                        Layout.alignment: Qt.AlignLeft
                        onClicked: Ln.register()
                    }
                    Item {
                        Layout.fillWidth: true
                    }

                    ToolButton {
                        text: "找回密码"
                        Layout.alignment: Qt.AlignRight
                        onClicked: Ln.recover()
                    }
                }

            }

        }
    }
}
